package com.hotel.project.demo.service.impl;

import com.hotel.project.demo.dao.hotel.HotelCommentDao;
import com.hotel.project.demo.domain.HotelCommentEntity;
import com.hotel.project.demo.domain.vo.CommentAndAnswerVo;
import com.hotel.project.demo.service.HotelCommentService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

@Service
public class HotelCommentServiceImpl extends CurdServiceImpl<HotelCommentEntity> implements HotelCommentService {

    @Resource
    private HotelCommentDao hotelCommentDao;

    /**
     * 酒店评论的删除 （逻辑删除）
     * @param id
     * @return
     */
    @Override
    @Transactional(rollbackFor = {Exception.class})
    public boolean deleteHotelCommentByCommentId(Long id) {
        if (id == null) {
            return false;
        }
        boolean flag= false;
        try {
            flag = ((HotelCommentDao)getBaseMapper()).deleteHotelCommentByCommentId(id);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return flag;
    }

    /**
     * 根据用户id查询用户评论
     * @param orderUserId 用户id
     * @return 查询的评论数据
     */
    @Override
    public CommentAndAnswerVo getCommentByOrderUserId(Long orderUserId) {
        if (orderUserId == null){
            return null;
        }
        return hotelCommentDao.getCommentByOrderUserId(orderUserId);
    }
}
